package jml.defaultimple.web;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import jml.def.Library;
import jml.defaultimple.util.JMLLoader;
import jml.defaultimple.util.JMLPluginManager;

@WebServlet("/refresh")
public class ServletRefresh extends HttpServlet
{
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, java.io.IOException
	{
		ServletContext application = getServletContext();
		
		// recargo la configuracion
		String configFile = application.getInitParameter("configFile");
		String configFileFullname = configFile;//application.getRealPath("") + "/" + configFile;

		Library library = JMLLoader.load(configFileFullname);
		application.setAttribute("library", library);	
		
		// notifico a los plugins que se acaba de cargar un titulo		
		JMLPluginManager.notifyAll("onRefresh", library);		

		
		request.getRequestDispatcher("index.jsp").forward(request, response);
	}
}